<%@ page language="java" contentType="text/html; charset=UTF-8"
	pageEncoding="UTF-8"%>
<%@ include file="/common/taglibs.jsp"%>
<div class="t_bar">资金概算（万元）</div> 
<table id="investedCapital" class="t_css" width="100%" autosum="y">  
      
         <tr> 
	          <td  class="TblHead" align="center"  width="10%">资金来源概算</td> 
	          <td   class="TblHead" align="center"  width="10%">来源合计</td> 
	          <td   class="TblHead" align="center"  width="16%">省财政拨款</td> 
	          <td  class="TblHead" align="center"   width="16%">市(县)财政拨款</td> 
	          <td  class="TblHead" align="center"   width="16%"> 其中：市财政拨款</td>
	          <td  class="TblHead" align="center"   width="16%"> 承担单位自筹研发投入</td>
	          <td  class="TblHead" align="center"   width="16%"> 其它经费来源</td>
			    
         </tr>
         
      
         
         <c:forEach begin="1" end="3"  var= "index" step="1" varStatus="item"> 
         	<tr align="center" >
			<td align="center">
		       	<input  class="" label="资金来源概算-->第${index}行-->年度" type="text"  style="text-align:right; width:40px;" name="budget/invest_deta[0${index}]/income_year_before" id="income_year_before${index}"  onfocus="InitInput.setNumber(this,4,0,0)"
		       		value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/income_year_before" />"/>年
			</td>
						
						 <td align="center" ><input type="text" name="budget/invest_deta[0${index}]/total_subtotal_before" id="total_${index}_subtotal"
							   class="gray"  disabled onfocus="InitInput.setNumber(this,9,2,2)" style="text-align:right; width:60px;" label="来源合计"   
							   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_subtotal_before" />"/>
				   		</td>
					   	
				   		<td align="center"><input type="text" name="budget/invest_deta[0${index}]/total_city_before" id="total_${index}_city"
						   onfocus="InitInput.setNumber(this,9,2,2)"  style="text-align:right; width:60px;" label="资金来源概算-->第${index}行-->省财政拨款"   
						   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_city_before" />" class=""
						   onchange="autoCalFund('investedCapital','total_city_before','total_city_all_temp' );countTotalbyRowbefore(); " />
					   </td>  
					   
				        <td align="center"><input type="text" name="budget/invest_deta[0${index}]/total_selfcapital_before" id="total_${index}_selfcapital"
							   onfocus="InitInput.setNumber(this,9,2,2)" style="text-align:right; width:60px;" label="资金来源概算-->第${index}行-->市(县)财政拨款"   
							   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_selfcapital_before" />" class=""
							   onchange="autoCalFund('investedCapital','total_selfcapital_before','total_selfcapital_all' );countTotalbyRowbefore();" />
						</td> 
				         
				 		 <td align="center"><input type="text" name="budget/invest_deta[0${index}]/total_other_before" id="total_${index}_other"
						   onfocus="InitInput.setNumber(this,9,2,2)" style="text-align:right; width:60px;" label="资金来源概算-->第${index}行-->其中：市财政拨款"  class=""
						   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_other_before" />"
						   onchange="autoCalFund('investedCapital','total_other_before','total_other_all' );"
						   />
						   <!--onchange="autoCalFund('investedCapital','total_other_before','total_other_all' );countTotalbyRowbefore();"  -->
				         </td>
				         
				         
				          <td align="center"><input type="text" name="budget/invest_deta[0${index}]/total_afford_org" id="total_${index}_afford"
						   onfocus="InitInput.setNumber(this,9,2,2)" style="text-align:right; width:60px;" label="资金来源概算-->第${index}行-->承担单位自筹研发投入"  class=""
						   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_afford_org" />"
						   onchange="autoCalFund('investedCapital','total_afford_org','total_afford_all' );countTotalbyRowbefore();"/>
				         </td>
				         
				          <td align="center"><input type="text" name="budget/invest_deta[0${index}]/total_other1_income" id="total_${index}_other1"
						   onfocus="InitInput.setNumber(this,9,2,2)" style="text-align:right; width:60px;" label="资金来源概算-->第${index}行-->其它经费来源"  class=""
						   value="<iris:xout select="$xmlData/data/budget/invest_deta[@seq_no='0${index}']/total_other1_income" />"
						   onchange="autoCalFund('investedCapital','total_other1_income','total_other1_all' );countTotalbyRowbefore();"/>
				         </td>
				         
			         <input name="budget/invest_deta[0${index}]@seq_no" value="0${index}"  type="hidden"/>	 
			</tr> 
         		
         </c:forEach>
         <tr> 
	          <td align="center" >概算金额</td> 
	          
	          <td align="center" >
	          <input type="text" name="budget/invest_deta/total_subtotal_all" id="total_subtotal_all"
				   class="gray" disabled style="text-align:right; width:60px;" label="概算金额"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_subtotal_all" />" 
				    />
			  </td> 
			  
	          <td align="center">
	          <input type="text" name="budget/invest_deta/total_city_money_all" id="total_city_all_temp"
				   class="gray" disabled style="text-align:right; width:60px;" label="省财政拨款"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_city_money_all" />"
				  	/> 
			  </td> 
			  
	          <td align="center">
	          <input type="text" name="budget/invest_deta/total_selfcapital_all" id="total_selfcapital_all"
				   class="gray" disabled style="text-align:right; width:60px;" label="市(县)财政拨款"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_selfcapital_all" />"
				  />
			</td> 
					    
	          <td align="center">
	          <input type="text" name="budget/invest_deta/total_other_all" id="total_other_all"
				   class="gray" disabled style="text-align:right; width:60px;" label="其中：市财政拨款"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_other_all" />"
				   />
			</td>
			
			 <td align="center">
	          <input type="text" name="budget/invest_deta/total_afford_all" id="total_afford_all"
				   class="gray" disabled style="text-align:right; width:60px;" label="承担单位自筹研发投入"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_afford_all" />"
				   />
			</td>
			
			 <td align="center">
	          <input type="text" name="budget/invest_deta/total_other1_all" id="total_other1_all"
				   class="gray" disabled style="text-align:right; width:60px;" label="其它经费来源"   
				   value="<x:out select="$xmlData/data/budget/invest_deta/total_other1_all" />"
				   />
			</td>
			
          </tr>   
          
</table> 
<script type="text/javascript">
$(function(){
	 if( typeof initMoneyforCity === 'function' ){
		 initMoneyforCity(); 
		}else{
		    //不存在或不是function
		}
	 
	 $("input[name$='total_subtotal_before']").each(function(){
		 $(this).focus();
		 $(this).blur();
	 }) ;
	 
	 countTotalbyRowbefore();
	
}) ;

var tempTableId2 = "investedCapital" ;
	 /**
	  * 将值以千分位显示
	  * @param value 数值
	  */
	 function thousandsNumber(value) {
	 	if (value == null || value == undefined || value == "") {
	 		return "";
	 	}
	 	var negative = '';
	 	var intVal = value.split(".")[0];
	 	var j = intVal.length;
	 	if(intVal.charAt(0) == '-'){
	 		negative = '-';
	 		intVal = intVal.substr(1, j);
	 	}
	 	j = intVal.length;
	 	for(var i=j-3; i>0; i=i-3){
	 		intVal = intVal.substr(0, i) + "," + intVal.substr(i, j);
	 	}
	 	if(value.split(".")[1] != null){
	 		return (negative + intVal + '.' + value.split(".")[1]);
	 	} else{
	 		return (negative + intVal);
	 	}
	 }
	
	
	 function request_amt(){
		 var ss=$("#total_subtotal").val();
		 $("#request_amt1").text(ss);
	 }
	  
	 function countTotalbyRowbefore(){
		 $("#" + tempTableId2).find(">tbody>tr:gt(0)").each(function(){
			var trObj  = $(this) ;
			var  total = trObj.find("td:eq(1)>input");
			var  itemVal1 = trObj.find("td:eq(2)>input").val();
			var  itemVal2 = trObj.find("td:eq(3)>input").val();
			var  itemVal3 = trObj.find("td:eq(4)>input").val();
			var  itemVal4 = trObj.find("td:eq(5)>input").val();
			var  itemVal5 = trObj.find("td:eq(6)>input").val();
			var  itemVal6 = trObj.find("td:eq(7)>input").val();
			var  itemVal7 = trObj.find("td:eq(8)>input").val();
			var  itemVal8 = trObj.find("td:eq(9)>input").val();
			if(itemVal1=='' || itemVal1  ==undefined){
				itemVal1 = 0;
			}
			if(itemVal2=='' || itemVal2  ==undefined){
				itemVal2 = 0;
			}
			if(itemVal3=='' || itemVal3  ==undefined){
				itemVal3 = 0;
			}
			if(itemVal4=='' || itemVal4  ==undefined){
				itemVal4 = 0;
			}
			if(itemVal5=='' || itemVal5  ==undefined){
				itemVal5 = 0;
			}
			if(itemVal6=='' || itemVal6  ==undefined){
				itemVal6 = 0;
			}
			if(itemVal7=='' || itemVal7  ==undefined){
				itemVal7 = 0;
			}
			if(itemVal8=='' || itemVal8  ==undefined){
				itemVal8 = 0;
			}
		//var number_row =parseFloat(itemVal1)*10000 + parseFloat(itemVal2 )*10000 + parseFloat(itemVal3)*10000 +
		//	parseFloat(itemVal4 )*10000 +parseFloat(itemVal5 )*10000 +parseFloat(itemVal6 )*10000 +parseFloat(itemVal7 )*10000 +parseFloat(itemVal8 )*10000
			//;
			var number_row =parseFloat(itemVal1)*10000 + parseFloat(itemVal2 )*10000 + parseFloat(itemVal4 )*10000
			+parseFloat(itemVal5 )*10000 +parseFloat(itemVal6 )*10000 +parseFloat(itemVal7 )*10000 +parseFloat(itemVal8 )*10000
			;
			number_row = number_row/10000 ;
			if (!$.isNumeric(number_row)){
				return  ;}
			total.val( formatNumberAuto(  number_row.toString()  , 9, 2, 2 )) ;
			 $("#totalMoney").text( $("#total_subtotal_all").val() ) ; //放到总经费 里面去 
		 });
		 
	 }
	 function addeventAddtable(){
		 
		 $("#" + tempTableId2).find(">tbody>tr:gt(1)").find("input").change(countTotalbyRowbefore) ;
		
	 } 
	 
	 function addeventAddtable1(){
		 addeventAddtable();
	
		 var total_city_all=$("#total_city_all").val();
		 var td3= $("#" + tempTableId2).find(">tbody>tr:eq(2)>td:eq(2)").find("input");
		 var td4= $("#" + tempTableId2).find(">tbody>tr:eq(3)>td:eq(2)").find("input");
		 var tr =$("#" + tempTableId2).find(">tbody>tr");
		 if(!!total_city_all){
			 if((tr.length-3)>1){
				 total_city_all=parseFloat(total_city_all);
				 if(total_city_all>=200){
					 td3.val(formatNumberAuto( (total_city_all*0.6).toString()  , 9, 2, 2 ));
					 td4.val(formatNumberAuto( (total_city_all*0.4).toString()  , 9, 2, 2 ));	
					}else{
						td3.val(formatNumberAuto(total_city_all.toString()  , 9, 2, 2 ));
						td4.val(formatNumberAuto("0", 9, 2, 2 ));
						
					}
			 }else{
			 		td3.val(formatNumberAuto(total_city_all.toString()  , 9, 2, 2 ));
			 }
		 
		 	}
		 for(var i=4;i<tr.length-1;i++){
			 var td5= $("#" + tempTableId2).find(">tbody>tr:eq("+i+")>td:eq(2)").find("input");
			 td5.val(formatNumberAuto("0", 9, 2, 2 ));
		 }
		 countTotalbyRowbefore();
	}
	//金额自动计算 
	 function autoCalFund(tabid,endName,targetId){
		 var num=0.00 ;
		 $("#"+tabid).find("tr td input[name$="+endName + " ]").each(function(){
			if( $(this).val() =='' ||$(this).val() ==undefined )	{
				return  ; 
			}
			if (!$.isNumeric($(this).val())){
				return  ;}
			num =num*10000 +parseFloat($(this).val())*10000  ;
			num =num/10000 ;
			
		 });
		 $("#"+targetId).val(formatNumberAutoOther(num.toString(), 9, 4, 2));    
	 }
	 
</script>

